<?

session_start();

require("../../Misc.php");

define('_DEFAULT_START'   , 0);

$start      = $_POST["srcStart"];
$length     = $_POST["srcLength"] - $_POST["srcStart"];
$total      = $_POST["srcTotal"];
$serNumber  = $_POST["srcSerNumber"];

/**
* We only process
* if $serNumber is not null
* and start and length is not 0
*
*/
if($_POST["srcStart"]   == 0 &&
   $_POST["srcLength"]  == 0){

  echo  $serNumber;
}else{

  if(strlen($serNumber) > 0){

    /**
    * Check if it is
    * not _MANUAL_KEY_IN or _NO_NUMBER
    * YES: Process
    * NO : return not serNumber
    *
    */
    $strCheck = explode(_DEFAULT_SEPARATOR_02,
                        $serNumber);

    if($strCheck[_1ST] != _MANUAL_KEY_IN){

      if($start > 0){

        $serLength = $_POST["srcStart"] - _DEFAULT_START;

        $theSerial = substr($serNumber,
                            _DEFAULT_START,
                            $serLength);
      }else{

        $theSerial = "";
      }

      $theNumber = substr($serNumber,
                          $_POST["srcStart"],
                          $length);

      $end    = (int)$theNumber + ((int)$total - 1);

      $end    = Misc::addDigit2($length, (string) $end).
               (string)$end;

      $result = $serNumber.
                "-".
                $theSerial.
                $end;

      echo  $result;
    }else{

      echo  $serNumber;
    }
  }else{

    echo $serNumber;
  }
}
?>